package com.flask.colorpicker.cameralibrary.state;

import com.flask.colorpicker.cameralibrary.view.CameraView;

import ohos.agp.graphics.SurfaceOps;
import ohos.app.Context;

/**
 * Camera Machine
 */
public class CameraMachine implements State {
    private final Context mContext;
    private State mState;
    private final CameraView mView;

    private final State mPreviewState; // 浏览状态(空闲)
    private final State mBorrowPictureState; // 浏览图片

    public CameraMachine(
            Context context, CameraView view) {
        this.mContext = context;
        mPreviewState = new PreviewState(this);
        mBorrowPictureState = new BorrowPictureState(this);
        // 默认设置为空闲状态
        this.mState = mPreviewState;
        this.mView = view;
    }

    /**
     * getView
     *
     * @return CameraView
     */
    public CameraView getView() {
        return mView;
    }

    /**
     * get Context
     *
     * @return Context
     */
    public Context getContext() {
        return mContext;
    }

    /**
     * set State
     *
     * @param state State
     */
    public void setState(State state) {
        this.mState = state;
    }

    /**
     * 获取浏览图片状态
     *
     * @return State
     */
    public State getBorrowPictureState() {
        return mBorrowPictureState;
    }

    /**
     * 获取空闲状态
     *
     * @return State
     */
    public State getPreviewState() {
        return mPreviewState;
    }

    /**
     * start
     *
     * @param holder holder
     * @param screenProp screenProp
     */
    @Override
    public void start(SurfaceOps holder, float screenProp) {
        mState.start(holder, screenProp);
    }

    /**
     * stop
     */
    @Override
    public void stop() {
        mState.stop();
    }

    /**
     * focus
     *
     * @param xx xx
     * @param yy yy
     */
    @Override
    public void focus(float xx, float yy) {
        mState.focus(xx, yy);
    }

    /**
     * switchCamera
     *
     * @param holder holder
     * @param screenProp screenProp
     */
    @Override
    public void switchCamera(SurfaceOps holder, float screenProp) {
        mState.switchCamera(holder, screenProp);
    }

    /**
     * restart
     */
    @Override
    public void restart() {
        mState.restart();
    }

    /**
     * capture
     */
    @Override
    public void capture() {
        mState.capture();
    }

    /**
     *
     */
    @Override
    public void record() {
        mState.record();
    }

    @Override
    public void stopRecord(boolean isShort, long time) {
        mState.stopRecord(isShort, time);
    }

    @Override
    public void cancel(SurfaceOps holder, float screenProp) {
        mState.cancel(holder, screenProp);
    }

    @Override
    public void confirm() {
        mState.confirm();
    }

    @Override
    public void zoom(float zoom, int type) {
        mState.zoom(zoom, type);
    }

    @Override
    public void flash(int mode) {
        mState.flash(mode);
    }

    /**
     * get State
     *
     * @return State
     */
    public State getState() {
        return this.mState;
    }
}
